package com.hunt.service.impl;

import com.github.pagehelper.PageHelper;
import com.hunt.dao.ManagementMapper;
import com.hunt.model.dto.PageInfo;
import com.hunt.service.UserPaymentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author nine
 * @date 2024/3/15/015
 * @Description
 */
@Service
@Transactional
public class UserPaymentInfoServiceImpl implements UserPaymentInfoService {
    @Autowired
    private ManagementMapper managementMapperForPaymentInfo;

    @Override
    public PageInfo selectPage(int page, int rows, String sort, String order,
                               String username, String phone, String accountTimeBegin, String accountTimesEnd,
                               String paymentTimeBegin, String paymentTimeEnd) {
        //对时间参数处理（去掉"-")
        accountTimeBegin = removeDashIfNotEmpty(accountTimeBegin);
        accountTimesEnd = removeDashIfNotEmpty(accountTimesEnd);
        paymentTimeBegin = removeDashIfNotEmpty(paymentTimeBegin);
        paymentTimeEnd = removeDashIfNotEmpty(paymentTimeEnd);
        int counts = managementMapperForPaymentInfo.selectCountsForPaymentInfo(sort,order,username,phone,accountTimeBegin,accountTimesEnd,paymentTimeBegin,paymentTimeEnd);
        PageHelper.startPage(page,rows);
        List userPaymentInfoList = managementMapperForPaymentInfo.selectAllPaymentInfo(sort,order,username,phone,accountTimeBegin,accountTimesEnd,paymentTimeBegin,paymentTimeEnd);
        PageInfo pageInfo = new PageInfo(counts, userPaymentInfoList);
        return pageInfo;
    }

    private static String removeDashIfNotEmpty(String date) {
        if (date != null && !date.isEmpty()) {
            return date.replace("-", "");
        }
        return date;
    }
}
